package com.corgi.kotlin.kotlin.service

import com.corgi.kotlin.kotlin.domain.TestPeople
import com.corgi.kotlin.kotlin.repository.TestPeopleRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * @title: TestPeopleService
 * @description:
 * @author: dengmiao
 * @create: 2019-10-15 11:45
 **/
interface TestPeopleService {

    /**
     * 按lastName查询
     */
    fun findByLastName(lastName: String): List<TestPeople>?

    /**
     * 新增
     */
    fun create(testPeople: TestPeople): TestPeople?

    /**
     * 查询
     */
    fun retrieve(): MutableIterable<TestPeople>?
}

@Service
class TestPeopleServiceImpl : TestPeopleService {
    override fun retrieve(): MutableIterable<TestPeople>? {
        return testPeopleRepository?.findAll()
    }

    override fun create(testPeople: TestPeople): TestPeople? {
        return testPeopleRepository?.save(testPeople)
    }

    override fun findByLastName(lastName: String): List<TestPeople>? {
        return testPeopleRepository?.findByLastName(lastName)
    }

    @Autowired
    val testPeopleRepository: TestPeopleRepository? = null
}